<?php
	require_once(realpath(dirname(__FILE__)) . "/../../classes/Message.class.php");
	require_once(realpath(dirname(__FILE__)) . "/../../classes/Messagedesc.class.php");
	
	/* Substitutions de type message */
		
	function substitmessage($texte){


	    preg_match_all("`\#MESSAGE_([^\(]+)\(([^\)]+)\)`", $texte, $cut);

	    $tab1 = "";
	    $tab2 = "";

	    for($i=0; $i<count($cut[1]); $i++){
			$message = new Message();
			$message->charger($cut[2][$i]);
			$messagedesc = new Messagedesc();
			$messagedesc->charger($message->id, $_SESSION['navig']->lang);

			if($cut[1][$i] == "TITRE") {
				$tab1[$i] = "#MESSAGE_" . $cut[1][$i] . "(" . $cut[2][$i] . ")";
		        $tab2[$i] = $messagedesc->titre;			
			}
	
			else if($cut[1][$i] == "CHAPO") {
				$tab1[$i] = "#MESSAGE_" . $cut[1][$i] . "(" . $cut[2][$i] . ")";
		        $tab2[$i] = $messagedesc->chapo;			
			}
			
			else if($cut[1][$i] == "DESCRIPTION") {
				$tab1[$i] = "#MESSAGE_" . $cut[1][$i] . "(" . $cut[2][$i] . ")";
		        $tab2[$i] = $messagedesc->description;			
			}

	    }

	    $texte = str_replace($tab1, $tab2, $texte);
	    return $texte;
	

	}
?>